<%--
 *  File:   uploadtableconfigedit.jsp
 *  Desc:	
 *
 *  Date	  :	 2013-05-31     
 *  Author	:  jeanhuang
 *
 *  Copyright (C) 2000 - 2005 Oval Technologies, Inc.
 *  All rights reserved.
 *
 *  This software is the confidential and proprietary information of Oval
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>
<%
	//init param
  String strModuleName = "DMS";
  String privilegeCode = "IMG0303";
  String contextPath = request.getContextPath();
String tablenamestr=request.getParameter("tablenameship");
if("".equals(tablenamestr) || tablenamestr  == null || "null".equals(tablenamestr)){
	tablenamestr = session.getAttribute("tablenameship")+"";
}
String struploadconfigid=request.getParameter("uploadconfigid")+"";
if(session.getAttribute("uploadconfigid")!=null){
	struploadconfigid=session.getAttribute("uploadconfigid")+"";
}
%>
<%@ include file="/inc/CommonHeader.inc" %>

<html>
<head>
<title>uploadtableconfigedit</title>
<PageFlow:CheckPageFlow pageName="p_uploadtableconfig"/>
<%@ include file="/inc/AlertError.inc" %>
<%
  Vector configtablesdatas = (Vector)pageContext.getAttribute("configtablesdatas");
  if(configtablesdatas == null) configtablesdatas = new Vector();
%>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="<%=contextPath%>/css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="<%=contextPath%>/css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="<%=contextPath%>/js/ScriptLib.js"></script>
<script language="JavaScript">

function clickComboCode(id)
{
  document.cform.delid.value = id;
}

function page_add()
{
    //if(!checkALLElems(document.getElementById("newdetail"))) return;
    //changedField();
    
    var primarykeyname=document.cform.addprimarykeyname.value;
    var foreignkeyname=document.cform.addforeignkeyname.value;
    var associatename=document.cform.addassociatename.value;
    var tablename=document.cform.addtablename.value;
    var tableseq=document.cform.addtableseq.value;
    
    if(tablename==null||tablename==""||tablename==-1){
    	alert("<%= message.getMessageDesc("VALUE_NOT_NULL", label.getLabelName("L_VtableName",false)) %>");
        return;
    }
    
    if(primarykeyname==null||primarykeyname==""||primarykeyname==-1){
    	alert("<%= message.getMessageDesc("VALUE_NOT_NULL", label.getLabelName("L_isPK",false)) %>");
        return;
    }
    if(foreignkeyname==null||foreignkeyname==""||foreignkeyname==-1){
    	alert("<%= message.getMessageDesc("VALUE_NOT_NULL", label.getLabelName("L_ForeignKey",false)) %>");
        return;
    }
     if(associatename==null||associatename==""||associatename==-1){
    	alert("<%= message.getMessageDesc("VALUE_NOT_NULL", label.getLabelName("L_ContactColumn",false)) %>");
        return;
    }
    if(tableseq==null||tableseq==""||tableseq==-1){
     	alert("<%= message.getMessageDesc("VALUE_NOT_NULL", label.getLabelName("L_SequenceSetting",false)) %>");
         return;
     }
    if(!checkFKequalPK()){
    	alert("<%= message.getMessageDesc("PrimaryKey_ForeignKey_Can_Not_Same", label.getLabelName("L_ContactColumn",false)) %>");
        return;
    }
    cform.actionname.value = "add";
    cform.target = "_self";
    isRunning = true;
    cform.submit();
}
function page_delete()
{

    if(!confirm("<%= message.getMessageDesc("ARE_YOU_SURE_DEL") %>")) return;
    cform.actionname.value = "delete";
    cform.target = "_self";
    isRunning = true;
    cform.submit();
}
function page_save()
{
    if(!checkForm(cform)) return;
    emptyToNull(cform);
    //checkForm(cform);
    cform.actionname.value = "save";
    cform.target = "_self";
    isRunning = true;
    cform.submit();
}
function changedField()
{
cform.columntypenew.options[cform.tablefield.selectedIndex].selected=true;
cform.columntype.value=cform.columntypenew.value;
}
function page_back(){
	parent.location.href="uploadConfigSummary.jsp?<%=OvalTools.randomURL()%>";
}

function setReadonly(){
	var numrows = cform.numrows.value;
	for(var i=0 ; i < numrows; i++){
		eval("cform.sourcesequence"+i).disabled = "disabled";
	}
}

function checklength(){
	var length  = cform.sourcesequence.value.length;
	if(length > 4){
		var value = cform.sourcesequence.value;
		cform.sourcesequence.value = value.substring(0, 4);
	}
}

var pktablename = false;
var fortablename = false;
var addpktablename = false;
var addfortablename = false;

function changesetvalue(idx){
	var a = "document.cform.primarykeyname"+idx;
	var b = "document.cform.foreignkeyname"+idx;

	eval(a).length = 1;
	eval(b).length = 1;

	var c = "document.cform.tablename"+idx;
	
	var textobj=eval(c).options[eval(c).selectedIndex].text;
	fortablename = textobj;
	pktablename = textobj;
}

function addchangesetvalue(){
	var a = "document.cform.addprimarykeyname";
	var b = "document.cform.addforeignkeyname";

	eval(a).length = 1;
	eval(b).length = 1;

	var c = "document.cform.addtablename";
	
	var textobj=eval(c).options[eval(c).selectedIndex].text;
	addfortablename = textobj;
	addpktablename = textobj;
}

function setforginevalue(idx){
	  if (!fortablename) {
	  	return;
	  }

	  var a = "document.cform.foreignkeyname"+idx;
	  eval(a).length=1;

	  var  datahandler = new  DataHandler() ;
	  datahandler.add_params("tablename" ,fortablename,"String");
	  datahandler.add_params("ispk" ,'N',"String");
	  datahandler.add_params("languagecode" ,"<%=strLanguageCode %>","String");
	  datahandler.add_job("j_gettableinfo");
	   
	  datahandler.getResultFromVector("columndatas","columnname" ,"columnname","document.cform.foreignkeyname"+idx);
	  datahandler.runDataHandler();
	  
	  fortablename = false;
}

function addsetforginevalue(){
	  if (!addfortablename) {
	  	return;
	  }

	  var a = "document.cform.addforeignkeyname";
	  eval(a).length=1;

	  var  datahandler = new  DataHandler() ;
	  datahandler.add_params("tablename" ,addfortablename,"String");
	  datahandler.add_params("ispk" ,'N',"String");
	  datahandler.add_params("languagecode" ,"<%=strLanguageCode %>","String");
	  datahandler.add_job("j_gettableinfo");
	   
	  datahandler.getResultFromVector("columndatas","columnname" ,"columnname","document.cform.addforeignkeyname");
	  datahandler.runDataHandler();
	  
	  addfortablename = false;
}

function setkeyvalue(idx){
	  if (!pktablename) {
	  	return;
	  }
	  var a = "document.cform.primarykeyname"+idx;
	  eval(a).length=1;
	  
	  var  datahandler = new  DataHandler() ;
	  datahandler.add_params("tablename" ,pktablename,"String");
	  datahandler.add_params("ispk" ,'Y',"String");
	  datahandler.add_params("languagecode" ,"<%=strLanguageCode %>","String");
	  datahandler.add_job("j_gettableinfo");
	   
	  datahandler.getResultFromVector("columndatas","columnname" ,"columnname","document.cform.primarykeyname"+idx);
	  datahandler.runDataHandler();
	  
	  pktablename = false;

}

function addsetkeyvalue(){
	  if (!addpktablename) {
	  	return;
	  }
	  var a = "document.cform.addprimarykeyname";
	  eval(a).length=1;
	  
	  var  datahandler = new  DataHandler() ;
	  datahandler.add_params("tablename" ,addpktablename,"String");
	  datahandler.add_params("ispk" ,'Y',"String");
	  datahandler.add_params("languagecode" ,"<%=strLanguageCode %>","String");
	  datahandler.add_job("j_gettableinfo");
	   
	  datahandler.getResultFromVector("columndatas","columnname" ,"columnname","document.cform.addprimarykeyname");
	  datahandler.runDataHandler();
	  
	  addpktablename = false;

}

function checkFKequalPK(){
	var pkvalue=document.cform.addprimarykeyname.value;
	var fkvalue=document.cform.addforeignkeyname.value;
	if(pkvalue==fkvalue){
		return false;
	}
	return true;
}

</script>
<body style="overflow: auto;">
<form name="cform" method="post" action="<%=contextPath%>/Dispatcher" >
  <input type="hidden" name="pagename" value="p_uploadtableconfig">
  <input type="hidden" name="actionname">
  <custom:hidden property="uploadconfigid" value="<%=struploadconfigid %>" />
  <custom:hidden property="tablenameship" value="<%=tablenamestr %>" />
  <input type="hidden" name="numrows" value="<%= configtablesdatas.size() %>">

<table border=0 cellpadding=0 cellspacing=0 width="100%">
  <tr>
    <td valign=top>
      <table border=0 cellpadding=1 cellspacing=0 width="100%">
        <tr>
          <td bgcolor=#000000 style="PADDING-BOTTOM: 1px; PADDING-LEFT: 1px; PADDING-RIGHT: 1px; PADDING-TOP: 0px">
            <table bgcolor=#000000 border=0 cellpadding=0 cellspacing=0 width="100%">
              <tr>
                <td  bgcolor=#ffffff style="PADDING-BOTTOM: 3px; PADDING-LEFT: 3px; PADDING-RIGHT: 3px; PADDING-TOP: 3px">
                  <div id=div2 style="HEIGHT: 415px; OVERFLOW: auto">
                    <table border="1" cellspacing="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" align="center" width="100%" cellpadding="1">

<%--    top function buttons    --%>
<% if(!isView){%>
                    <tr>
                        <td colspan="20" class="td_right">
                        
                          <a onclick="page_add()"><custom:button type="2" label="L_Add" imgsrc="add_btn.gif" border="0"/></a>
                       	  <a onclick="page_save()"><custom:button type="2" label="L_Save" imgsrc="save_btn.gif" border="0"/></a>
                          <%if(configtablesdatas.size()>0 ){%>
                          <a onclick="page_delete();"><custom:button type="2" label="L_Delete" imgsrc="delete_btn.gif" border="0"/></a>
                          <%}%>
                        </td>
                      </tr>
<%}%>
<tr  class="deepblue-left"> 
	<td width="22" class="title_center">&nbsp;</td>
	<td width="30%" class="title_center"><%= label.getLabelName("L_VtableName") %><font color="red">*</font></td>
	<td width="20%" class="title_center"><%= label.getLabelName("L_isPK") %><%= label.getLabelName("L_ElementName") %><font color="red">*</font></td>
	<td width="20%" class="title_center"><%= label.getLabelName("L_ForeignKey") %><%= label.getLabelName("L_ElementName") %><font color="red">*</font></td>
	<td class="title_center"><%= label.getLabelName("L_ContactColumn") %><font color="red">*</font></td>
	<td width="13%" class="title_center"><a href="javascript:page_summary('orderby','tableseq')"><%= label.getLabelName("L_SequenceSetting") %></a><font color="red">*</font></td>
</tr>
<span id="olddetail" >
						
						  <%
				             int j = 0;
				             String strClassType = new String();
				             Integer nDefaultId = new Integer(-1);
				             boolean bHasChecked = false;
				          %>
                      <logic:iterate id="onerow" collection="<%= configtablesdatas %>" indexId="idx">
                      <%
				            HashMap hashdatas = (HashMap)pageContext.getAttribute("onerow");
                      
				            String strIsDisabled = new String("");
				            String strIsChecked = new String("");
				   
				            if(j%2 == 1){
				              strClassType = "td-listrom";
				            }else{
				              strClassType = "";
				            }
				           if(!bHasChecked)
				            {
				        	  nDefaultId = (Integer)(hashdatas.get("uploadtablesconfigid"));
				              strIsChecked = "Checked";
				              bHasChecked = true;
				              
				            }
				            j++;
         			 %>
                      <tr>
                        <td width="30">
	                  		<input id="deletes<%=JspHelper.filterNull(j)%>" type="radio" name="checkdept"  value=<%=JspHelper.filterNull( hashdatas.get("uploadtablesconfigid") )%> class="checkbox" <%=JspHelper.filterNull( strIsChecked)%> onClick="javascript:clickComboCode('<%=JspHelper.filterNull( hashdatas.get("uploadtablesconfigid") )%>')">
	                   		<custom:hidden property="uploadtablesconfigid" name="onerow" colIndex="<%=idx%>" />
                        </td>
                        <td>
                        	<%
                        	String tablenamemethod = "changesetvalue("+(j-1)+");";
                        	%>
                        	<custom:select optionsName="alltables" name="onerow" property="tablename" optionInnerTextKey="tablename" optionValueKey="tablename" defaultValue="---------" onchange="<%=tablenamemethod %>" command="notnull" label="L_TableName" colIndex="<%=idx %>"/>
                        </td>
                        <td>
                        	<%
                        	String primarykeynamemethod = "setkeyvalue("+(j-1)+");";
                        	%>
                        	<custom:select name="onerow" property="primarykeyname" optionsName="configtablesdatas" optionValueKey="primarykeyname" optionInnerTextKey="primarykeyname" defaultValue="---------" onclick="<%=primarykeynamemethod %>" command="notnull" label="L_isPK" colIndex="<%=idx %>"/>
                        </td>
                        <td>
                        	<%
                        	String foreignkeynamemethod = "setforginevalue("+(j-1)+");";
                        	%>
                        	<custom:select name="onerow" property="foreignkeyname" optionsName="configtablesdatas" optionValueKey="foreignkeyname" optionInnerTextKey="foreignkeyname" defaultValue="---------" onclick="<%=foreignkeynamemethod %>" command="notnull" label="L_ForeignKey" colIndex="<%=idx %>"/>
                        <td>
                        	<custom:select name="onerow" property="associatename" optionsName="allshipcolumns" optionValueKey="columnname" optionInnerTextKey="columnname" command="notnull" label="L_ContactColumn" colIndex="<%=idx %>"/>
                        </td>
                       	<td>
                       		<custom:text name="onerow" property="tableseq" size="20" command="notnull"  label="L_SequenceSetting" colIndex="<%=idx %>"/>
                       	</td>
                   </tr>
                      
                      </logic:iterate>
</span>
<input type="hidden" name="delid" value="<%=JspHelper.filterNull( nDefaultId )%>" />
<% if(!isView){%>
<span id="newdetail" >
                      <tr >
                        <td>&nbsp;</td>
                        <td>
                       	 <custom:select optionsName="alltables" name="newdetail" property="addtablename" optionInnerTextKey="tablename" optionValueKey="tablename" defaultValue="---------" onchange="addchangesetvalue()"/>
                        </td>
                        
                        <td><custom:select name="newdetail" property="addprimarykeyname" optionsName="columndatas" optionValueKey="columnname" optionInnerTextKey="columnname" defaultValue="---------" onclick="addsetkeyvalue()"/></td>
                        <td><custom:select name="newdetail" property="addforeignkeyname" optionsName="columndatas" optionValueKey="columnname" optionInnerTextKey="columnname" defaultValue="---------" onclick="addsetforginevalue()"/></td>
                        <td><custom:select name="newdetail" property="addassociatename" optionsName="allshipcolumns" optionValueKey="columnname" optionInnerTextKey="columnname"/></td>
                        <td><custom:text name="newdetail" property="addtableseq" size="20"/></td>
                      </tr>

</span>
<script>
//changedField();
</script>
<%}%>

                    </table>
                  </div>
                </td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
      <table width="100%" cellspacing="0" cellpadding="0">
         <tr><td class="summary_top"></td></tr>
         <tr>
           <td class="td_center">
          
             <a onclick="page_back();"><custom:button type="1" label="L_Back" imgsrc="new.gif" border="0" style="width:60"/></a>
          
           </td>
         </tr>
      </table>
    </td>
  </tr>
</table>
</form>
</body>
<script>
	//setReadonly();
</script>
</html>